<template>
  <div>
    <div v-if="userInfo.userId===1" style="padding: 8px 28px">提示：当前登陆的账号为系统超级管理员，您可以看到所有的审批任务。超级管理员审核会一次性完成，无需二次审批。</div>
    <BasicTable @register="registerTable" @fetch-success="onFetchSuccess">
      <template #toolbar>
        <a-button  v-if="hasPermission('addDept')" type="primary" @click="handleCreate">
          新增
        </a-button>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
               label:'审批',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            // {
            //                  label:'删除',
            //   icon: 'ant-design:delete-outlined',
            //   color: 'error',
            //   popConfirm: {
            //     title: '是否确认删除',
            //     confirm: handleDelete.bind(null, record),
            //   },
            // },
          ]"
        />
      </template>
    </BasicTable>
    <Modal @register="registerModal" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  import { defineComponent, nextTick } from 'vue';
  import { useUserStore } from '/@/store/modules/user';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  // import { StockList, StockDel } from '/@/api/stock/stock';
  import {  myTaskUserList, TaskCenterDel } from '/@/api/taskCenter/taskCenter';

  import { useModal } from '/@/components/Modal';
  import Modal from './Modal.vue';

  import { columns, searchFormSchema } from './schema.data';
  import { usePermission } from '/@/hooks/web/usePermission';

  export default defineComponent({
    name: 'TaskCenter',
    components: { BasicTable, Modal, TableAction },
    setup() {
      const userStore = useUserStore();
      const userInfo = userStore.getUserInfo;


      const { hasPermission } = usePermission();
      const [registerModal, { openModal }] = useModal();
      const [registerTable, { reload, expandAll,setProps }] = useTable({
        title: '我的待审批任务列表',
        api:  myTaskUserList,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        isTreeTable: true,
        pagination:{
          pageSize: 10,
          pageSizeOptions:['10', '20', '50', '100', '500']

        },
        striped: false,
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        canResize: false,
        actionColumn: {
          width:'80px',
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
        afterFetch:(e)=>{
          setProps({
            title:`我的待审批任务列表(${e.length})`
          })
        }
      });

      function handleCreate() {
        openModal(true, {
          isUpdate: false,
        });
      }

      function handleEdit(record: Recordable) {
        openModal(true, {
          record,
          isUpdate: true,
        });
      }

      function handleDelete(record: Recordable) {
        TaskCenterDel({id:record.id}).then(() => {
          reload();
        });
      }

      function handleSuccess() {
        reload();
      }
      function onFetchSuccess() {
        nextTick(expandAll);
      }
      return {
        userStore,
        userInfo,
        registerTable,
        registerModal,
        handleCreate,
        handleEdit,
        handleDelete,
        handleSuccess,
        hasPermission,
        onFetchSuccess,
      };
    },
  });
</script>
